package cn.com.backstage.controller;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.com.api.entity.*;
import cn.com.api.service.*;
import cn.com.backstage.controller.base.U_bonusBaseController;

import cn.com.util.*;

@Controller
@RequestMapping(Utils.SYS_BACKSTAGE + "/")
public class U_bonusController extends U_bonusBaseController {

	private static Logger logger = Logger.getLogger(U_bonusController.class);

	@Autowired
	private ApiU_bonusService apiU_bonusService;
	@Autowired
	private ApiU_advertService apiU_advertService;
	@Autowired
	private ApiU_advert_resourceService apiU_advert_resourceService;
	@Autowired
	private ApiT_member_entrepreneurService apiT_member_entrepreneurService;
	@Autowired
	private U_labelService labelService;

	/**
	 * 新增或者编辑
	 * 
	 * @return
	 */
	@RequestMapping(value = "bonus-add")
	public void bonus_add(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 红包参数
		String id = request.getParameter("id");
		// String count = request.getParameter("count");
		String summy = request.getParameter("summy");
		String title = request.getParameter("title");
		String resource_type = request.getParameter("resource_type");// 广告的type
		String count_charge = request.getParameter("count_charge");
		String count_free = request.getParameter("count_free");
		String show_times = request.getParameter("show_times");
		String latitude = request.getParameter("latitude");
		String longitude = request.getParameter("longitude");
		String distance_range = request.getParameter("distance_range");

		String max_money = request.getParameter("max_money");
		String min_money = request.getParameter("min_money");
		String start_time = request.getParameter("start_time");
		String end_time = request.getParameter("end_time");

		String bless_word = request.getParameter("bless_word");
		String ent_id = request.getParameter("ent_id");
		String entrepreneurid = ent_id.split("_")[0];
		String userid = ent_id.split("_")[1];

		String[] labels = request.getParameterValues("label");

		String interest_key = "";// 兴趣爱好
		if (labels != null && labels.length > 0) {
			interest_key = Util.join(":", labels);
		}
		// 区别全品红包/推荐红包

		// 地区信息 格式：江苏省/常州市/溧阳市
		String province = "";
		String city = "";
		String area = "";
		String[] regioninfos = request.getParameterValues("regioninfo");
		for (String regioninfo : regioninfos) {
			if (regioninfo != null && !"".equals(regioninfo.trim())) {
				String[] regions = regioninfo.split("/");
				province += ":" + regions[0];
				city += ":" + regions[1];
				area += ":" + regions[2];
			}
		}
		if (!"".equals(province)) {
			province = province.substring(1);
		}
		if (!"".equals(city)) {
			city = city.substring(1);
		}
		if (!"".equals(area)) {
			area = area.substring(1);
		}

		// 广告参数
		String covers = request.getParameter("covers");

		// 广告轮播图
		String[] resources = request.getParameterValues("resources");
		String videoresource = request.getParameter("videoresource");

		Map<String, Object> map = new HashMap<String, Object>();
		// add
		if (id == null || (id.trim()).equals("")) {

			// 插入广告对应的红包
			ApiU_bonus u_bonus = new ApiU_bonus();

			u_bonus.setUser_id("");
			u_bonus.setSummy(new BigDecimal(summy));
			u_bonus.setTitle(title);
			u_bonus.setAdd_time(DateUtil.nowTimeToString());
			u_bonus.setIs_expire(0);
			u_bonus.setUser_id(userid);
			if ("0".equals(resource_type)) {
				u_bonus.setType(1);
			} else { // 视频广告时，广告的缩略图地址为视频的地址
				u_bonus.setType(2);
			}

			u_bonus.setDuring_time(0);
			u_bonus.setCount_charge(Integer.valueOf(count_charge));
			u_bonus.setCount_free(Integer.valueOf(count_free));
			u_bonus.setCount(Integer.valueOf(count_charge) + Integer.valueOf(count_free));
			u_bonus.setShow_times(Integer.valueOf(show_times) * 10000);
			u_bonus.setLatitude(latitude);
			u_bonus.setLongitude(longitude);

			u_bonus.setMax_money(new BigDecimal(max_money));
			u_bonus.setMin_money(new BigDecimal(min_money));
			u_bonus.setBless_word(bless_word);

			int ret_boolen = apiU_bonusService.U_bonusInsertion(u_bonus);

			if (ret_boolen > 0) {
				Integer bonus_id = u_bonus.getId();

				ApiU_advert u_advert = new ApiU_advert();

				u_advert.setAdv_name(title);
				// u_advert.setAdv_desc(adv_desc);
				u_advert.setZan_count(0);
				u_advert.setPosition_id(3);
				u_advert.setAdd_time(Util.CurrentTime());
				u_advert.setProvince(province);
				u_advert.setCity(city);
				u_advert.setStatus(1);
				u_advert.setIs_pay(1);
				u_advert.setStart_time(start_time);
				u_advert.setEnd_time(end_time);
				u_advert.setArea(area);

				if (regioninfos.length == 1) {
					u_advert.setLongitude(longitude);
					u_advert.setLatitude(latitude);
					u_advert.setDistance_range(Long.valueOf(distance_range));
				}

				if (interest_key != null && !"".equals(interest_key.trim())) {
					u_advert.setInterest_key(interest_key.trim());
				}

				u_advert.setEnt_id(entrepreneurid);// 企业id
				u_advert.setAdd_uid(userid);// 发布人id

				u_advert.setResource_type(Integer.valueOf(resource_type));
				if ("1".equals(resource_type)) {// 视频广告时，广告的缩略图地址为视频的地址
					u_advert.setCovers(videoresource);
				} else {
					covers = covers.replace(",", ""); // 排除前段多图片地址
					u_advert.setCovers(covers);
				}
				u_advert.setProvince(province);
				u_advert.setCity(city);
				u_advert.setArea(area);
				u_advert.setTotal_amount(new BigDecimal(summy));

				// u_advert.setAge_range(age_range);
				// u_advert.setJob_title(job_title);

				ApiT_member_entrepreneur apiT_member_entrepreneur = apiT_member_entrepreneurService
						.findT_member_entrepreneurById(Integer.valueOf(ent_id.split("_")[0]));
				u_advert.setLogo(apiT_member_entrepreneur.getLogo_img());
				/*
				 * u_advert.setLatitude(latitude);
				 * u_advert.setLongitude(longitude);
				 */
				u_advert.setShow_times(Integer.valueOf(show_times));
				u_advert.setBonus_id(bonus_id.toString());
				u_advert.setAdd_time(DateUtil.nowTimeToString());

				// u_advert.setSort(sort);
				// u_advert.setDetail_url(detail_url);
				// u_advert.setDistance_range(distance_range);
				// u_advert.setStart_time(start_time);
				// u_advert.setEnd_time(end_time);
				// u_advert.setAddress(address);

				apiU_advertService.U_advertInsertion(u_advert);
				Integer adv_id = u_advert.getId();

				// 插入广告轮播图
				if ("0".equals(resource_type)) {// 图片广告
					for (String str_resouce : resources) {
						if (str_resouce.length() > 0) {
							ApiU_advert_resource u_advert_resource = new ApiU_advert_resource();
							u_advert_resource.setAdvert_id(adv_id.toString());
							u_advert_resource.setResource_url(str_resouce);
							apiU_advert_resourceService.insertU_advert_resource(u_advert_resource);
						}
					}
				} else {// 视频广告
					ApiU_advert_resource u_advert_resource = new ApiU_advert_resource();
					u_advert_resource.setAdvert_id(adv_id.toString());
					u_advert_resource.setResource_url(videoresource);
					apiU_advert_resourceService.insertU_advert_resource(u_advert_resource);
				}
			}
		} else {// edit
			map.clear();
			map.put("id", id);
			ApiU_bonus u_bonus = apiU_bonusService.getBonusInfoByMap(map);
			// 修改红包信息
			u_bonus.setSummy(new BigDecimal(summy));
			u_bonus.setTitle(title);
			u_bonus.setAdd_time(DateUtil.nowTimeToString());
			u_bonus.setIs_expire(0);
			if ("0".equals(resource_type)) {
				u_bonus.setType(1);
			} else {
				u_bonus.setType(2);
			}
			u_bonus.setDuring_time(0);
			u_bonus.setCount_charge(Integer.valueOf(count_charge));
			u_bonus.setCount_free(Integer.valueOf(count_free));
			u_bonus.setCount(Integer.valueOf(count_charge) + Integer.valueOf(count_free));
			u_bonus.setShow_times(Integer.valueOf(show_times));
			u_bonus.setLatitude(latitude);
			u_bonus.setLongitude(longitude);
			u_bonus.setShow_times(Integer.valueOf(show_times));
			u_bonus.setMax_money(new BigDecimal(max_money));
			u_bonus.setMin_money(new BigDecimal(min_money));

			u_bonus.setBless_word(bless_word);
			apiU_bonusService.updateU_bonus(u_bonus);

			// 跟新关联的广告信息
			map.clear();
			map.put("bonus_id", Integer.valueOf(id));
			ApiU_advert advert = u_bonus.getAdvert();

			advert.setAdv_name(title);
			// u_advert.setAdv_desc(adv_desc);
			// advert.setZan_count(0);
			advert.setPosition_id(3);
			// u_advert.setAdd_time(Util.CurrentTime());
			advert.setStatus(1);

			if (interest_key != null && !"".equals(interest_key.trim())) {
				advert.setInterest_key(interest_key.trim());
			}

			advert.setEnt_id(ent_id.split("_")[0]);// 企业id
			advert.setAdd_uid(ent_id.split("_")[1]);// 发布人id

			advert.setResource_type(Integer.valueOf(resource_type));
			advert.setProvince(province);
			advert.setCity(city);
			advert.setArea(area);
			advert.setTotal_amount(new BigDecimal(summy));

			// u_advert.setAge_range(age_range);
			// u_advert.setJob_title(job_title);

			/*
			 * u_advert.setLatitude(latitude); u_advert.setLongitude(longitude);
			 */
			advert.setShow_times(Integer.valueOf(show_times));
			// u_advert.setBonus_id(bonus_id.toString());
			// u_advert.setAdd_time(DateUtil.nowTimeToString());

			// u_advert.setSort(sort);
			// u_advert.setDetail_url(detail_url);
			// u_advert.setDistance_range(distance_range);
			// u_advert.setStart_time(start_time);
			// u_advert.setEnd_time(end_time);
			// u_advert.setAddress(address);

			covers = covers.replace(",", ""); // 排除前段多图片地址
			advert.setCovers(covers);
			advert.setStart_time(start_time);
			advert.setEnd_time(end_time);
			apiU_advertService.updateU_advert(advert);
			Integer adv_id = advert.getId();
			// 插入广告轮播图
			if ("0".equals(resource_type)) {// 图片广告
				apiU_advert_resourceService.deleteAdvertResource(advert.getId());
				for (String str_resouce : resources) {
					if (str_resouce.length() > 0) {
						ApiU_advert_resource u_advert_resource = new ApiU_advert_resource();
						u_advert_resource.setAdvert_id(adv_id.toString());
						u_advert_resource.setResource_url(str_resouce);
						apiU_advert_resourceService.insertU_advert_resource(u_advert_resource);
					}
				}
			} else {// 视频广告
				apiU_advert_resourceService.deleteAdvertResource(Integer.valueOf(id));
				ApiU_advert_resource u_advert_resource = new ApiU_advert_resource();
				u_advert_resource.setAdvert_id(adv_id.toString());
				u_advert_resource.setResource_url(videoresource);
				apiU_advert_resourceService.insertU_advert_resource(u_advert_resource);
			}

		}
		//
		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put(Utils.MESSAGE, "添加成功！");
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 进入新增或者编辑页面(全品红包广告添加)
	 * 
	 * @return
	 */
	@RequestMapping(value = "u_bonus-add-pre")

	public ModelAndView u_bonus_add_pre(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView("forward:/backstage/u_bonus_add.jsp");
		Map<String, Object> map = new HashMap<String, Object>();
		String bonusid = request.getParameter("id");
		if (bonusid != null && !"".equals(bonusid)) {
			map.put("id", bonusid);
			ApiU_bonus apiU_bonus = apiU_bonusService.getBonusInfoByMap(map);
			mv.addObject("u_bonus", apiU_bonus);
		}
		// 获取企业主信息
		map.clear();
		map.put("status", 1);
		PageInfo page = new PageInfo();
		page.setCurrentPage(1);
		page.setShowCount(10);
		List<ApiT_member_entrepreneur> entrepreneurs = apiT_member_entrepreneurService
				.findT_member_entrepreneursByMap(map, page);
		mv.addObject("entrepreneurs", entrepreneurs);
		return mv;
	}

	/**
	 * 进入新增或者编辑页面(推荐红包广告添加)
	 * 
	 * @return
	 */
	@RequestMapping(value = "u_bonus_recommend-add-pre")
	public ModelAndView u_bonus_recommend_add_pre(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ModelAndView mv = new ModelAndView("forward:/backstage/u_bonus_recommend_add.jsp");
		if (request.getParameter("id") != null) {
			String id = request.getParameter("id");
			ApiU_bonus u_bonus = apiU_bonusService.findU_bonusById(Integer.valueOf(id));
			mv.addObject("u_bonus", u_bonus);
		}
		// 获取企业主信息
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("status", 1);
		PageInfo page = new PageInfo();
		page.setCurrentPage(1);
		page.setShowCount(5);
		List<ApiT_member_entrepreneur> entrepreneurs = apiT_member_entrepreneurService
				.findT_member_entrepreneursByMap(paramMap, page);
		mv.addObject("entrepreneurs", entrepreneurs);

		// 回去兴趣爱好标签库
		List<U_label> alllabels = labelService.getAlllabels(1);
		mv.addObject("alllabels", alllabels);
		return mv;
	}

	/**
	 * 进入新增或者编辑页面(现场红包添加)
	 * 
	 * @return
	 */
	@RequestMapping(value = "bonus_han-add-pre")
	public ModelAndView bonus_han_add_pre(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView("forward:/backstage/u_bonus_han_add.jsp");
		if (request.getParameter("id") != null) {
			String id = request.getParameter("id");
			ApiU_bonus u_bonus = apiU_bonusService.findU_bonusById(Integer.valueOf(id));
			mv.addObject("u_bonus", u_bonus);
		}
		// 获取企业主信息
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("status", 1);
		PageInfo page = new PageInfo();
		page.setCurrentPage(1);
		page.setShowCount(5);
		List<ApiT_member_entrepreneur> entrepreneurs = apiT_member_entrepreneurService
				.findT_member_entrepreneursByMap(paramMap, page);
		mv.addObject("entrepreneurs", entrepreneurs);

		// 回去兴趣爱好标签库
		List<U_label> alllabels = labelService.getAlllabels(1);
		mv.addObject("alllabels", alllabels);
		return mv;
	}

	/**
	 * 现场红包提交
	 * 
	 * @return
	 */
	@RequestMapping(value = "bonus_han-add")
	public void bonus_han_add(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 红包参数
		String id = request.getParameter("id");
		// String count = request.getParameter("count");
		String summy = request.getParameter("summy");
		String title = request.getParameter("title");
		String resource_type = request.getParameter("resource_type");// 广告的type
		String count_charge = request.getParameter("count_charge");
		String count_free = request.getParameter("count_free");
		String show_times = request.getParameter("show_times");
		String latitude = request.getParameter("latitude");
		String longitude = request.getParameter("longitude");
		String max_money = request.getParameter("max_money");
		String min_money = request.getParameter("min_money");

		String start_time = request.getParameter("start_time");
		String end_time = request.getParameter("end_time");

		String bless_word = request.getParameter("bless_word");
		String ent_id = request.getParameter("ent_id");
		String entrepreneurid = ent_id.split("_")[0];
		String userid = ent_id.split("_")[1];

		String[] labels = request.getParameterValues("label");
		String interest_key = "";// 兴趣爱好
		if (labels != null && labels.length > 0) {
			interest_key = Util.join(":", labels);
		}

		// 地区信息 格式：江苏省/常州市/溧阳市
		String province = "";
		String city = "";
		String area = "";
		String regioninfo = request.getParameter("regioninfo");
		if (regioninfo != null && !"".equals(regioninfo.trim())) {
			String[] regions = regioninfo.split("/");
			province = regions[0];
			city = regions[1];
			area = regions[2];
		}

		// 广告参数
		String covers = request.getParameter("covers");

		// 广告轮播图
		String[] resources = request.getParameterValues("resources");
		String videoresource = request.getParameter("videoresource");

		Map<String, Object> map = new HashMap<String, Object>();
		// add
		if (id == null || (id.trim()).equals("")) {

			// 插入广告对应的红包
			ApiU_bonus u_bonus = new ApiU_bonus();

			u_bonus.setUser_id("");
			u_bonus.setSummy(new BigDecimal(summy));
			u_bonus.setTitle(title);
			u_bonus.setAdd_time(DateUtil.nowTimeToString());
			u_bonus.setIs_expire(0);
			u_bonus.setUser_id(userid);
			if ("0".equals(resource_type)) {
				u_bonus.setType(1);
			} else {
				u_bonus.setType(2);
			}

			u_bonus.setDuring_time(0);
			u_bonus.setCount_charge(Integer.valueOf(count_charge));
			u_bonus.setCount_free(Integer.valueOf(count_free));
			u_bonus.setCount(Integer.valueOf(count_charge) + Integer.valueOf(count_free));
			u_bonus.setShow_times(Integer.valueOf(show_times));
			u_bonus.setLatitude(latitude);
			u_bonus.setLongitude(longitude);

			u_bonus.setShow_times(Integer.valueOf(show_times));
			u_bonus.setMax_money(new BigDecimal(max_money));
			u_bonus.setMin_money(new BigDecimal(min_money));
			u_bonus.setBless_word(bless_word);

			int ret_boolen = apiU_bonusService.U_bonusInsertion(u_bonus);

			if (ret_boolen > 0) {
				Integer bonus_id = u_bonus.getId();

				ApiU_advert u_advert = new ApiU_advert();

				u_advert.setAdv_name(title);
				// u_advert.setAdv_desc(adv_desc);
				u_advert.setZan_count(0);
				u_advert.setPosition_id(8); // 8:喊红包
				u_advert.setAdd_time(Util.CurrentTime());
				u_advert.setProvince(province);
				u_advert.setCity(city);
				u_advert.setStatus(1);
				u_advert.setIs_pay(1);
				u_advert.setStart_time(start_time);
				u_advert.setEnd_time(end_time);
				u_advert.setArea(area);

				if (interest_key != null && !"".equals(interest_key.trim())) {
					u_advert.setInterest_key(interest_key.trim());
				}

				if ("1".equals(resource_type)) {// 视频广告时，广告的缩略图地址为视频的地址
					u_advert.setCovers(videoresource);
				} else {
					covers = covers.replace(",", ""); // 排除前段多图片地址
					u_advert.setCovers(covers);
				}

				u_advert.setEnt_id(entrepreneurid);// 企业id
				u_advert.setAdd_uid(userid);// 发布人id

				u_advert.setResource_type(Integer.valueOf(resource_type));
				u_advert.setProvince(province);
				u_advert.setCity(city);
				u_advert.setArea(area);
				u_advert.setTotal_amount(new BigDecimal(summy));

				// u_advert.setAge_range(age_range);
				// u_advert.setJob_title(job_title);

				ApiT_member_entrepreneur apiT_member_entrepreneur = apiT_member_entrepreneurService
						.findT_member_entrepreneurById(Integer.valueOf(ent_id.split("_")[0]));
				u_advert.setLogo(apiT_member_entrepreneur.getLogo_img());

				/*
				 * u_advert.setLatitude(latitude);
				 * u_advert.setLongitude(longitude);
				 */

				u_advert.setShow_times(Integer.valueOf(show_times));
				u_advert.setBonus_id(bonus_id.toString());
				u_advert.setAdd_time(DateUtil.nowTimeToString());
				apiU_advertService.U_advertInsertion(u_advert);
				Integer adv_id = u_advert.getId();

				// 插入广告轮播图
				if ("0".equals(resource_type)) {// 图片广告
					for (String str_resouce : resources) {
						if (str_resouce.length() > 0) {
							ApiU_advert_resource u_advert_resource = new ApiU_advert_resource();
							u_advert_resource.setAdvert_id(adv_id.toString());
							u_advert_resource.setResource_url(str_resouce);
							apiU_advert_resourceService.insertU_advert_resource(u_advert_resource);
						}
					}
				} else {// 视频广告
					ApiU_advert_resource u_advert_resource = new ApiU_advert_resource();
					u_advert_resource.setAdvert_id(adv_id.toString());
					u_advert_resource.setResource_url(videoresource);
					apiU_advert_resourceService.insertU_advert_resource(u_advert_resource);
				}
			}
		} else {// edit
			ApiU_bonus u_bonus = apiU_bonusService.findU_bonusById(Integer.valueOf(id));
			// 修改红包信息
			u_bonus.setSummy(new BigDecimal(summy));
			u_bonus.setTitle(title);
			u_bonus.setAdd_time(DateUtil.nowTimeToString());
			u_bonus.setIs_expire(0);
			if ("0".equals(resource_type)) {
				u_bonus.setType(1);
			} else {
				u_bonus.setType(2);
			}
			u_bonus.setDuring_time(0);
			u_bonus.setCount_charge(Integer.valueOf(count_charge));
			u_bonus.setCount_free(Integer.valueOf(count_free));
			u_bonus.setCount(Integer.valueOf(count_charge) + Integer.valueOf(count_free));
			u_bonus.setShow_times(Integer.valueOf(show_times));
			u_bonus.setLatitude(latitude);
			u_bonus.setLongitude(longitude);
			u_bonus.setShow_times(Integer.valueOf(show_times));
			u_bonus.setMax_money(new BigDecimal(max_money));
			u_bonus.setMin_money(new BigDecimal(min_money));

			u_bonus.setBless_word(bless_word);
			apiU_bonusService.updateU_bonus(u_bonus);

			// 跟新关联的广告信息
			map.clear();
			map.put("bonus_id", Integer.valueOf(id));
			ApiU_advert advert = apiU_advertService.findAdvertsInfoByMap(map);

			advert.setAdv_name(title);
			// u_advert.setAdv_desc(adv_desc);
			// advert.setZan_count(0);
			advert.setPosition_id(3);
			// u_advert.setAdd_time(Util.CurrentTime());
			advert.setStatus(1);

			if (interest_key != null && !"".equals(interest_key.trim())) {
				advert.setInterest_key(interest_key.trim());
			}

			advert.setEnt_id(ent_id.split("_")[0]);// 企业id
			advert.setAdd_uid(ent_id.split("_")[1]);// 发布人id

			advert.setResource_type(Integer.valueOf(resource_type));
			advert.setProvince(province);
			advert.setCity(city);
			advert.setArea(area);
			advert.setTotal_amount(new BigDecimal(summy));

			// u_advert.setAge_range(age_range);
			// u_advert.setJob_title(job_title);

			/*
			 * u_advert.setLatitude(latitude); u_advert.setLongitude(longitude);
			 */
			advert.setShow_times(Integer.valueOf(show_times));
			// u_advert.setBonus_id(bonus_id.toString());
			// u_advert.setAdd_time(DateUtil.nowTimeToString());

			// u_advert.setSort(sort);
			// u_advert.setDetail_url(detail_url);
			// u_advert.setDistance_range(distance_range);
			// u_advert.setStart_time(start_time);
			// u_advert.setEnd_time(end_time);
			// u_advert.setAddress(address);

			covers = covers.replace(",", ""); // 排除前段多图片地址
			advert.setCovers(covers);
			advert.setStart_time(start_time);
			advert.setEnd_time(end_time);
			apiU_advertService.updateU_advert(advert);
			Integer adv_id = advert.getId();
			// 插入广告轮播图
			if ("0".equals(resource_type)) {// 图片广告
				apiU_advert_resourceService.deleteAdvertResource(advert.getId());
				for (String str_resouce : resources) {
					if (str_resouce.length() > 0) {
						ApiU_advert_resource u_advert_resource = new ApiU_advert_resource();
						u_advert_resource.setAdvert_id(adv_id.toString());
						u_advert_resource.setResource_url(str_resouce);
						apiU_advert_resourceService.insertU_advert_resource(u_advert_resource);
					}
				}

			} else {// 视频广告
				ApiU_advert_resource u_advert_resource = new ApiU_advert_resource();
				u_advert_resource.setAdvert_id(adv_id.toString());
				u_advert_resource.setResource_url(videoresource);
				apiU_advert_resourceService.insertU_advert_resource(u_advert_resource);
			}

		}
		//
		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put(Utils.MESSAGE, "添加成功！");
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

}
